package com.guoning.office_system.service.impl;

import com.guoning.office_system.mapper.WorkOrderMapper;
import com.guoning.office_system.model.User;
import com.guoning.office_system.model.WorkOrder;
import com.guoning.office_system.service.WorkOrderService;
import com.guoning.office_system.vo.Criteria;
import com.guoning.office_system.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WorkOrderServiceImpl implements WorkOrderService {

    @Autowired
    WorkOrderMapper workOrderMapper;

    @Override
    public PageBean<WorkOrder> selectByQueryCondition(Criteria criteria, PageBean pageBean) {
        criteria.addExtField("pageIndex", pageBean.getPageIndex() * pageBean.getPageSize());
        criteria.addExtField("pageSize", pageBean.getPageSize());
        Long totalCount = workOrderMapper.selectCountByQueryCondition(criteria);
        List<WorkOrder> list = workOrderMapper.selectByQueryCondition(criteria);
        pageBean.setTotalCount(totalCount);
        pageBean.setResultList(list);
        return pageBean;
    }

    @Override
    public Long selectCountByQueryCondition(Criteria criteria) {
        return null;
    }

    @Override
    public int updateHaveRead(List<WorkOrder> workOrderList) {
        for (int i=0; i<workOrderList.size(); i++){
            if(workOrderList.get(i).getEnableStatus() != 1){
                workOrderList.remove(i);
            }else{
                workOrderList.get(i).setEnableStatus(2);
            }
        }
        return workOrderMapper.updateEnableStatus(workOrderList);
    }

    @Override
    public int updateHaveToDo(List<WorkOrder> workOrderList) {
        for (int i=0; i<workOrderList.size(); i++){
            if(workOrderList.get(i).getEnableStatus() != 2){
                workOrderList.remove(i);
            }else{
                workOrderList.get(i).setEnableStatus(3);
            }
        }
        return workOrderMapper.updateEnableStatus(workOrderList);
    }

    @Override
    public List<Map> getEnableStatusItemAndCount(Long userId) {
        return workOrderMapper.getEnableStatusItemAndCount(userId);
    }

    @Override
    public int updateForDeleteById(Long id) {
        return workOrderMapper.updateForDeleteById(id);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return 0;
    }

    @Override
    public Long insert(WorkOrder record) {
        workOrderMapper.insert(record);
        return record.getId();
    }

    @Override
    public int insertSelective(WorkOrder record) {
        return 0;
    }

    @Override
    public WorkOrder selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(WorkOrder record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(WorkOrder record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(WorkOrder record) {
        return 0;
    }
}